package com.ruoyi.lm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lm.domain.LmMessage;
import com.ruoyi.lm.service.ILmMessageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息Controller
 * 
 * @author ruoyi
 * @date 2020-09-25
 */
@Controller
@RequestMapping("/phone/lm/message")
public class LmMessageControllerPhone extends BaseController
{
    private String prefix = "lm/message";

    @Autowired
    private ILmMessageService lmMessageService;

    /**
     * 查询消息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmMessage lmMessage)
    {
        List<LmMessage> list = lmMessageService.selectLmMessageListPhone(lmMessage);

        lmMessageService.updateMessageUserId(lmMessage.getMessageUser());
        return getDataTable(list);
    }

    /**
     * 查询维度消息条数
     */
    @PostMapping("/getUnreadMessages")
    @ResponseBody
    public AjaxResult getUnreadMessages(String messageUser)
    {
        LmMessage lmMessage = new LmMessage();
        lmMessage.setMessageUser(messageUser);
        List<LmMessage> list = lmMessageService.selectLmMessageCountPhone(lmMessage);
        return success("查询成功", list.size());
    }

    /**
     * 新增保存消息
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody LmMessage lmMessage)
    {
        lmMessage.setMessageType("系统");
        return toAjax(lmMessageService.insertLmMessage(lmMessage));
    }

    /**
     * 修改保存消息
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody LmMessage lmMessage)
    {
        return toAjax(lmMessageService.updateLmMessage(lmMessage));
    }

    /**
     * 删除消息
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmMessageService.deleteLmMessageByIds(ids));
    }
}
